package com.fujimana.rockincat.restree.sample.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;

import com.fujimana.rockincat.restree.sample.entity.UserData;

public class UserDataDao {

	private static final UserDataDao INSTANCE = new UserDataDao();

	public static final UserDataDao getInstance() {
		return INSTANCE;
	}

	private UserDataDao() {
		try {
			Class.forName("org.hsqldb.jdbcDriver");
			Connection connection = DriverManager.getConnection(
					"jdbc:hsqldb:mem:User", "sa", "");

			Statement st = connection.createStatement();
			st.executeUpdate("create table USER(id int, name varchar, phone varchar, email varchar, address varchar)");
			
		} catch (Exception e) {
		}

	}

	public UserData find(String id) {
		
		try {
			Connection connection = DriverManager.getConnection(
					"jdbc:hsqldb:mem:User", "sa", "");
			Statement st = connection.createStatement();
			
			 ResultSet rs = st.executeQuery("select * from USER where id="+id);
			 
			 rs.next();
			 
			 UserData u = new UserData();
			 
			 u.setName(rs.getString("name"));
			 u.setEmail(rs.getString("phone"));
			 u.setEmail(rs.getString("email"));
			 u.setPhone(rs.getString("address"));
			 
			 return u;
		} catch (SQLException e) {
		}
		
		return null;
	}

	public Collection<UserData> findAll() {
		return null;
	}

	public void update(UserData data, String id) {
	}

	public void delete(String id) {
	}

	public void insert(UserData data, String id) {
	}

}
